/*
https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Native_messaging
https://developer.mozilla.org/zh-CN/docs/Mozilla/Add-ons/WebExtensions/Content_scripts

On startup, connect to the "ping_pong" app.
*/
console.log("begin connectNative.");
var myPort = browser.runtime.connect({name:"port-from-cs"});
console.log("end connectNative.");

function post2Native(mesg){
  console.log("page sending:["+mesg+"]");
  myPort.postMessage(mesg);
}

function onNativeMsg(lst){
  console.log("page add listener .");
  myPort.onMessage.addListener(lst);
}

console.log("begin exportFunction.");
exportFunction(post2Native, window, {defineAs:'post2Native'});
exportFunction(onNativeMsg, window, {defineAs:'onNativeMsg'});
console.log("end exportFunction.");